<script setup>
import { ref } from 'vue'
import { employeeLoginService } from '@/api/employee/login'
import { ElMessage } from 'element-plus'
import { useRouter } from 'vue-router'
import { useEmployeeStore } from '@/stores'
const formModel = ref({
  username: '',
  password: ''
})
const rules = {
  username: [
    { required: true, message: '请输入用户名', trigger: 'change' },
    { min: 3, max: 10, message: '用户名必须在5-10位', trigger: 'change' }
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'change' },
    { pattern: /^\S{6,15}$/, message: '密码必须是 6 - 15 位 的非空字符' }
  ]
}
const formRef = ref()
const router = useRouter()
const employeeStore = useEmployeeStore()
const login = async () => {
  await formRef.value.validate()
  const res = await employeeLoginService(formModel.value)
  console.log(res)
  if (res.data.code === 1) {
    ElMessage.success('登陆成功')
    employeeStore.setEmployeeInfo(res.data.data)
    await router.push('/')
  } else {
    ElMessage.error(res.data.msg)
  }
}
</script>
<template>
  <!-- LOGIN FORM CREATION -->
  <div class="background"></div>
  <div class="container">
    <div class="item">
      <h2 class="logo"><i class="bx bxl-xing"></i>YijiaCuisine</h2>
      <div class="text-item">
        <h2>
          <span> Management System </span>
          <br /><br />
          <span> For YijiaCuisine </span>
        </h2>
        <!--        <p>益佳肴后台管理端</p>-->
      </div>
    </div>
    <div class="login-section">
      <div class="form-box login">
        <el-form :model="formModel" :rules="rules" ref="formRef">
          <h2>登 陆</h2>
          <el-form-item prop="username" style="margin-top: 20px">
            <label>用户名</label>
            <el-input v-model="formModel.username" />
          </el-form-item>
          <el-form-item prop="password" style="margin-top: 20px">
            <label>密码</label>
            <el-input type="password" v-model="formModel.password" />
          </el-form-item>
          <el-button class="btn" style="margin-top: 40px" @click="login"
            >登 入</el-button
          >
        </el-form>
      </div>
    </div>
  </div>
  <!-- SIGN UP FORM CREATION -->
</template>

<style scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'poppins', sans-serif;
}
body {
  height: 100vh;
  width: 100%;
  background: #000;
}
.background {
  background: url('@/assets/backgroun3.jpg') no-repeat center;
  background-size: cover;
  height: 97vh;
  width: 100%;
  filter: blur(10px);
}

.header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  padding: 25px 13%;
  background: transparent;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 100;
}
.navbar a {
  position: relative;
  font-size: 16px;
  color: #fff;
  margin-right: 30px;
  text-decoration: none;
}
.navbar a::after {
  content: '';
  position: absolute;
  left: 0;
  width: 100%;
  height: 2px;
  background: #fff;
  bottom: -5px;
  border-radius: 5px;
  transform: translateY(10px);
  opacity: 0;
  transition: 0.5s ease;
}
.navbar a:hover:after {
  transform: translateY(0);
  opacity: 1;
}
.search-bar {
  width: 250px;
  height: 45px;
  background-color: transparent;
  border: 2px solid #fff;
  border-radius: 6px;
  display: flex;
  align-items: center;
}
.search-bar input {
  width: 100%;
  background-color: transparent;
  border: none;
  outline: none;
  color: #fff;
  font-size: 16px;
  padding-left: 10px;
}
.search-bar button {
  width: 40px;
  height: 100%;
  background: transparent;
  outline: none;
  border: none;
  color: #fff;
  cursor: pointer;
}
.search-bar input::placeholder {
  color: #fff;
}
.search-bar button i {
  font-size: 22px;
}
.container {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 75%;
  height: 550px;
  margin-top: 20px;
  background: url('@/assets/backgroun3.jpg') no-repeat center;
  background-size: cover;
  border-radius: 20px;
  overflow: hidden;
}
.item {
  position: absolute;
  top: 0;
  left: 0;
  width: 58%;
  height: 100%;
  color: #fff;
  background: transparent;
  padding: 80px;
  display: flex;
  justify-content: space-between;
  flex-direction: column;
}
.item .logo {
  color: #fff;
  font-size: 30px;
}
.text-item h2 {
  font-size: 40px;
  line-height: 1;
}
.text-item p {
  font-size: 16px;
  margin: 20px 0;
}
.social-icon a i {
  color: #fff;
  font-size: 24px;
  margin-left: 10px;
  cursor: pointer;
  transition: 0.5s ease;
}
.social-icon a:hover i {
  transform: scale(1.2);
}
.container .login-section {
  position: absolute;
  top: 0;
  right: 0;
  width: calc(100% - 70%);
  height: 100%;
  color: #fff;
  backdrop-filter: blur(10px);
}

.login-section .form-box {
  position: absolute;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
}
.login-section .form-box.register {
  transform: translateX(430px);
  transition: transform 0.6s ease;
  transition-delay: 0s;
}
.login-section.active .form-box.register {
  transform: translateX(0px);
  transition-delay: 0.7s;
}

.login-section .form-box.login {
  transform: translateX(0px);
  transition: transform 0.6s ease;
  transition-delay: 0.7s;
}
.login-section.active .form-box.login {
  transform: translateX(430px);
  transition-delay: 0s;
}

.login-section .form-box h2 {
  text-align: center;
  font-size: 25px;
}

.form-box .input-box {
  width: 340px;
  height: 50px;
  border-bottom: 2px solid#fff;
  margin: 30px 0;
  position: relative;
}
.input-box input {
  width: 100%;
  height: 100%;
  background: transparent;
  border: none;
  outline: none;
  font-size: 16px;
  padding-right: 28px;
}
.input-box label {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  font-size: 16px;
  font-weight: 600;
  pointer-events: none;
  transition: 0.5s ease;
}
.input-box .icon {
  position: absolute;
  top: 13px;
  right: 0;
  font-size: 19px;
}
.input-box input:focus ~ label,
.input-box input:valid ~ label {
  top: -5px;
}
.remember-password {
  font-size: 14px;
  font-weight: 500;
  margin: -15px 0 15px;
  display: flex;
  justify-content: space-between;
}
.remember-password label input {
  accent-color: #fff;
  margin-right: 3px;
}
.remember-password a {
  color: #fff;
  text-decoration: none;
}
.remember-password a:hover {
  text-decoration: underline;
}
.btn {
  width: 100%;
  height: 45px;
  outline: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background: rgb(101, 159, 52);
  font-size: 16px;
  color: #fff;
  box-shadow: rgba(0, 0, 0, 0.4);
}
.create-account {
  font-size: 14.5px;
  text-align: center;
  margin: 25px;
}
.create-account p a {
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}
.create-account p a:hover {
  text-decoration: underline;
}
</style>
